package com.mingqijia.gassafety.db.mapper;

import com.mingqijia.gassafety.db.entity.DeviceState;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.mingqijia.gassafety.db.entity.vo.*;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.springframework.stereotype.Repository;

import java.util.List;
import java.util.Map;

/**
 * <p>
 * 报警器设备状态更新表 Mapper 接口
 * </p>
 *
 * @author guoliang.lao
 * @since 2022-08-04
 */
@Mapper
@Repository
public interface DeviceStateMapper extends BaseMapper<DeviceState> {

    List<Integer> getConsumerIdsByDeviceStatus(@Param("spId") String spId,
                                 @Param("statusList") List<Integer> statusList);

    List<DeviceStateVO> getDeviceStateList(LatestLogListVO params);

    DeviceStateVO getDeviceStateByImei(@Param("imei")String imei,@Param("spId") String spId);

    List<Map<String,Object>> getDeviceStateSummary(String spId);

    DeviceState selectByDeviceId(@Param("id") Object id,@Param("spId") Object spId);

    List<Map<String, Object>> getWarningDeviceGas(String spId);

    List<Map<String, Object>> getWarningDeviceAsst(String spId);
    /**
     * 查询对应spid下设备最新状态
     * @param hangzhouSpId
     * @return
     */
    List<DeviceState> selectNewestList(@Param("spId") String hangzhouSpId);

    void updateByImei(@Param("imei") String imei, @Param("spId") String spId);

    List<Map<String, Object>> getDeviceStateSummaryBySpIds(@Param("spIds") List<String> spIds,@Param("funcCodes") List<String> funcCodes);

    void updateDeviceState(@Param("imei") String imei, @Param("spId") String spId,
                           @Param("deviceStatus") Integer deviceStatus);

    void updateDeviceStateCyc(@Param("imei") String imei, @Param("spId") String spId,
                           @Param("deviceStatus") Integer deviceStatus);

    List<DeviceStateVO> queryDeviceStateByImeiSpId(@Param("imei")String imei,@Param("spId") String spId);

    List<ConsumerDeviceStatVO> getConsumerDeviceState(@Param("spIds") List<String> spIds,
                                                      @Param("consumerIds") List<Integer> consumerIds);

    //查询所有故障和报警状态的设备
    List<DeviceState> queryDeviceState(@Param("spIds") List<String> spIds);

    //查询job所需数据
    List<DeviceState> queryForDeviceCycleNotice(@Param("spId") String spId,
                                                @Param("preIds") List<String> preIds,
                                                @Param("period") Integer period);

    //获取告警处理工单关联的设备是报警状态的数量
    Integer getWorkOrderImeisByStates(@Param("spId") String spId,
                                           @Param("workorderId") Long workorderId,
                                           @Param("deviceStatusList") List<Integer> deviceStatus);

    //获取故障处理工单关联的设备是故障状态的数量
    Integer getWorkOrderImeisByStatesBoken(@Param("spId") String spId,
                                      @Param("workorderId") Long workorderId,
                                      @Param("deviceStatusList") List<Integer> deviceStatus);


    //根据状态获取设备列表
    List<ScreenSmallBellItemVO> getScreenSmallBellList(ScreenSmallBellListReqVO params);
}
